package com.dj.mingkong.portal.biz.controller.system;

import com.dj.mingkong.common.infrastructure.base.dto.rest.RestResponse;
import com.dj.mingkong.portal.biz.controller.system.vo.response.DictionaryVo;
import com.dj.mingkong.portal.biz.service.system.DictionaryService;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotBlank;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 数据字典管理
 *
 * @author zenglonghui
 * @date: 2023/4/14 16:59
 */
@RestController
@RequestMapping("/dict")
public class DictionaryController {
    @Resource
    private DictionaryService dictionaryService;

    /**
     * 获取树形结构数据列表
     *
     * @return List<DictionaryVo>
     */
    @GetMapping("/listTree")
    public RestResponse<List<DictionaryVo>> listTree() {

        return RestResponse.success(dictionaryService.listTree());
    }

    /**
     * 根据父Key获取子列表
     *
     * @param key 参数
     * @return List<DictionaryVo>
     */
    @GetMapping("/getByParentKey/{key}")
    public RestResponse<List<DictionaryVo>> getByParentKey(@PathVariable("key") @NotBlank String key) {

        return RestResponse.success(dictionaryService.getByParentKey(key));
    }
}
